<template>
  <div class="bock">
    <div class="bockTop">
      <img src="../../assets/logo.png" alt="" />
      <div class="txt" @click="toClick">返回首页</div>
    </div>
    <div class="bockContent">
      <div>
        <el-row>
          <el-col :span="7">
            <img src="../../assets/touxiang.png" alt=""
          /></el-col>
          <el-col :span="17"
            ><div class="text" style="margin-top: 10px">欢迎登录</div>
            <div class="text">吉林省网安数字警务室</div></el-col
          >
        </el-row>
        <el-form
          ref="loginForm"
          :model="formData"
          :rules="loginRules"
          class="login-form"
        >
          <el-form-item prop="name">
            <el-input
              placeholder="请输入账号名称或手机号码"
              v-model="formData.name"
            >
              <img
                slot="prefix"
                src="../../assets/yonghu.png"
                alt=""
                class="formImg"
              />
            </el-input>
          </el-form-item>
          <el-form-item prop="pass">
            <el-input
              placeholder="请输入密码"
              v-model="formData.pass"
              show-password
            >
              <img
                slot="prefix"
                src="../../assets/mima.png"
                alt=""
                class="formImg"
              />
            </el-input>
          </el-form-item>
          <el-form-item prop="code">
            <el-input
              placeholder="请输入图片验证码"
              v-model="formData.code"
              style="width: 70%"
            >
            </el-input>
            <span>
              <img
                :src="captchaPath"
                @click="getCaptcha()"
                alt=""
                class="yzmImg"
              />
            </span>
          </el-form-item>
          <el-form-item>
            <div class="operate">
              <el-checkbox v-model="formData.checked" class="ztSpan"
                >记住登录状态</el-checkbox
              >

              <span class="wjSpan" @click="reset"> 忘记密码? </span>
            </div>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              :loading="loading"
              @click.native.prevent="handleLogin"
              >登 录</el-button
            >
          </el-form-item>
          <el-form-item>
            <el-divider content-position="center" @click="register"
              >没有账号？立即注册</el-divider
            >
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div class="bottomMsg">
      <div>©Copyright © 2014-2022 QIANXIN.COM</div>
      <div>服务联系电话：0431-82098114</div>
      <div>备案序号：吉ICP备05001602号 吉公网安备： 22000002000002号</div>
    </div>
  </div>
</template>
<script>
import { basePath, basePath2 } from "@/common";
import { setToken, setInfo } from "@/utils/auth";
import { GetCaptcha, GetLogin } from "@/api/login";

export default {
  data() {
    return {
      loading: false,
      captchaPath: "",
      formData: {
        name: "",
        pass: "",
        uuid: "",
        code: "",
        checked: true,
      },
      loginRules: {
        name: [{ required: true, trigger: "blur", message: "请输入用户名" }],
        pass: [
          {
            required: true,
            trigger: "blur",
            message: "请输入密码",
          },
        ],
        code: [{ required: true, trigger: "blur", message: "请输入验证码" }],
      },
    };
  },
  methods: {
    handleLogin() {
      this.loading = true;
      this.$refs.loginForm.validate(async (valid) => {
        if (valid) {
          // let res = await GetLogin(this.loginForm);
          // console.log(res, "res==");
          // if (res.data.status == 200) {
          //   this.loading = false;
          //   setToken(res.data.response.token);
          //   let url = "";
          //   if (process.env.NODE_ENV == "development") {
          //     url = basePath;
          //   } else {
          //     url = basePath2;
          //   }
          //   window.location.href = url + "/#/?tk=" + res.data.response.token;
          // } else {
          //   this.loading = false;
          //   this.$message({
          //     message: res.data.msg,
          //     type: "error",
          //   });
          // }

          setToken("999HHAIO");
          setInfo({
            name: "王野",
            circleUrl:
              "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
          });
          let url = "";
          if (process.env.NODE_ENV == "development") {
            url = basePath;
          } else {
            url = basePath2;
          }
          window.location.href = url + "/#/?tk=999HHAIO";
        } else {
          this.loading = false;
          return false;
        }
      });
    },
    // 获取验证码
    async getCaptcha() {
      this.formData.uuid = this.getUUID();
      let res = await GetCaptcha({ uuid: this.formData.uuid });
      console.log(res, "res---");
      if (!res.data.success) {
        this.$message({
          type: "error",
          message: res.data.msg,
        });
      } else {
        this.captchaPath = res.data.response;
      }
    },
    getUUID() {
      return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
        /[xy]/g,
        function (c) {
          var r = (Math.random() * 16) | 0,
            v = c == "x" ? r : (r & 0x3) | 0x8;
          return v.toString(16);
        }
      );
    },
    toClick() {
      this.$router.push("/");
    },
    reset() {
      this.$router.push("/resetPassword");
    },
    register() {
      this.$router.push("/register");
    },
  },
  mounted() {
    this.getCaptcha();
  },
};
</script>
<style scoped>
.bock {
  width: 100%;
  height: 100%;
  background: url("../../assets/bgcLogin.jpg");
  background-size: cover; /* 或者使用 '100% 100%' 来确保覆盖整个视口 */
  background-position: center center; /* 确保图片居中 */
  background-repeat: no-repeat; /* 防止图片重复 */
}
.bockTop {
  height: 100px;
  display: flex;
  align-items: center;
  padding: 0 2%;
  background-color: #fff;
  opacity: 0.85;
}
.bockTop .txt {
  width: 100%;
  text-align: right;
  font-size: 16px;
  color: #333333;
  font-weight: 400;
  cursor: pointer;
  font-family: PingFangSC-Regular;
}
.bockContent {
  width: 600px;
  transform: scale(0.92);
  margin: 0 auto;
  margin-top: 72px;
  background-image: linear-gradient(180deg, #e3eeff 0%, #ffffff 13%);
  border: 1px solid rgba(203, 215, 234, 1);
  box-shadow: 0px 4px 9px 0px rgba(0, 0, 0, 0.36);
  border-radius: 3px;
}
.bockContent > div {
  width: 80%;
  margin: 5% auto;
}
.bockContent > div .text {
  font-size: 30px;
  color: #333333;
  font-weight: 500;
  font-family: PingFangSC-Medium;
}
.bottomMsg {
  width: 600px;
  margin: 16px auto;
  text-align: center;
  color: #fff;
  font-size: 14px;
  line-height: 40px;
}
.login-form {
  margin-top: 4.2%;
  margin-left: 2%;
}
/deep/ .el-input__inner {
  height: 48px;
  border: 1px solid rgba(153, 153, 153, 1);
  border-radius: 8px;
  padding: 0 40px;
  font-size: 16px;
  color: #666666;
  letter-spacing: 0;
  font-weight: 400;
}
/deep/ .el-input--prefix .el-input__inner {
  padding-left: 40px !important;
}
.formImg {
  vertical-align: middle;
  /* margin-top: 2%; */
  margin-top: 8px;
  margin-left: 10px;
}
.yzmImg {
  height: 48px;
  vertical-align: middle;
  cursor: pointer;
}
.operate span {
  display: inline-block;
  font-family: PingFangSC-Regular;
  font-size: 16px;
  width: 49%;
}

.operate .wjSpan {
  position: absolute;
  right: 0;
  text-align: right;
  color: #0065ff;
  font-weight: 400;
  cursor: pointer;
}
/deep/ .el-checkbox__label {
  font-size: 16px;

  font-family: PingFangSC-Regular;
  color: #333333 !important;
}
/deep/ .el-button--primary {
  width: 100%;
  height: 60px;
  background-color: #2e6be6;
  border: 1px solid rgba(46, 107, 230, 1);
  border-radius: 3px;
  font-family: PingFangSC-Regular;
  font-size: 20px;
  color: #ffffff;
  line-height: 22px;
  font-weight: 400;
}

/deep/ .el-divider__text {
  font-family: PingFangSC-Regular;
  font-size: 16px;
  color: #0065ff;
  letter-spacing: 0;
  line-height: 24px;
  font-weight: 400;
  cursor: pointer;
}
/deep/ .el-checkbox__inner {
  width: 18px;
  height: 18px;
  text-align: center;
}
/deep/ .el-checkbox__inner::after {
  left: 6px;
  top: 3px;
}
/deep/ .el-checkbox__input.is-checked .el-checkbox__inner {
  background-color: #2e6be6;
  border: 1px solid #2e6be6;
}
</style>